﻿using System;
using Microsoft.Extensions.Configuration;

namespace Aliyun.SmsSdk.AspNetCore
{
    public class AliyunSmsOptions
    {
        /// <summary>
		/// 产品名称:云通信短信API产品,开发者无需替换
		/// </summary>
		public string Product { get; set; } = "Dysmsapi";

        /// <summary>
        /// 产品域名,开发者无需替换
        /// </summary>
        public string Domain { get; set; } = "dysmsapi.aliyuncs.com";

        /// <summary>
        /// 开发者自己的AK(在阿里云访问控制台寻找)
        /// </summary>
        public string AccessKeyId { get; set; }

        /// <summary>
        /// 您的原始格式RSA私钥
        /// </summary>
        public string AccessKeySecret { get; set; }

        /// <summary>
        /// 短信模板
        /// </summary>
        public string TemplateCode { get; set; }

        /// <summary>
        /// 短信签名
        /// </summary>
        public string SignName { get; set; }

        public void SetOption(IConfigurationSection section)
        {
            if (section == null)
            {
                throw new ArgumentException(nameof(section));
            }

            var options = section.Get<AliyunSmsOptions>();
            SetOption(options);
        }

        public void SetOption(AliyunSmsOptions options)
        {
            if (options == null)
            {
                throw new ArgumentException(nameof(options));
            }

            this.Product = options.Product;
            this.Domain = options.Domain;
            this.AccessKeyId = options.AccessKeyId;
            this.AccessKeySecret = options.AccessKeySecret;
            this.TemplateCode = options.TemplateCode;
            this.SignName = options.SignName;
        }
    }
}
